package org.boge.sharpdoc.controller;

import com.github.pagehelper.PageInfo;
import org.boge.sharpdoc.bean.Customer;
import org.boge.sharpdoc.bean.Document;
import org.boge.sharpdoc.bean.DownloadHistory;
import org.boge.sharpdoc.bean.LayuiReturnData;
import org.boge.sharpdoc.service.DownloadHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("downloadHistory/admin")
public class DownloadHistoryController {
    @Autowired
    private DownloadHistoryService downloadHistoryService;

    @PostMapping("getAllDlHistory")
    @ResponseBody
    public LayuiReturnData getAllDlHistory(Integer index, Integer pageSize) {
        PageInfo<DownloadHistory> pageInfo = downloadHistoryService.getAllWithPage(index, pageSize);
        List<DownloadHistory> dls = pageInfo.getList();
        for (DownloadHistory d : dls) {
            Customer customer = new Customer();
            customer.setPhone(d.getCustomer().getPhone());
            Document document = new Document();
            document.setDocid(d.getDocument().getDocid());

            d.setCustomer(customer);
            d.setDocument(document);
        }
        return new LayuiReturnData(0, true, "数据查询成功！", (int) pageInfo.getTotal(), dls);
    }

    @GetMapping("downloadHistoryPage")
    public String downloadHistoryPage() {
        return "admin/downloadHistory";
    }
}